package com.kuanter.kuanterauto.adapter;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.activity.NewActivation;
import com.kuanter.kuanterauto.entity.AccountInfoNew;

public class ChargeAccountInfoJinEAdapter extends BaseAdapter {
	private Activity activity;
	private List<AccountInfoNew> chargeAccountInfoNewList;
	private TextView xuni_account;
	private TextView chargeConsumptionStyle;
	private List<AccountInfoNew> chargeAccountInfoNewListJiFen = new ArrayList<AccountInfoNew>();
	private List<AccountInfoNew> chargeAccountInfoNewListCiShu = new ArrayList<AccountInfoNew>();
	private double jiFen ;
	private double ciShu ;
	private int count = 0 ;
	private int jiFenCount = 0;
	private int ciShuCount = 0;
	private RelativeLayout rl_charge_account;
	
	public ChargeAccountInfoJinEAdapter(Activity activity,
			List<AccountInfoNew> chargeAccountInfoNewList) {
		super();
		this.activity = activity;
		this.chargeAccountInfoNewList = chargeAccountInfoNewList;
		for(AccountInfoNew accountInfoNew : chargeAccountInfoNewList){
			if(accountInfoNew.getUnit().equals("积分")){
				chargeAccountInfoNewListJiFen.add(accountInfoNew);
				jiFen += Double.valueOf(accountInfoNew.getNumber());
			}else if(accountInfoNew.getUnit().equals("次数")){
				chargeAccountInfoNewListCiShu.add(accountInfoNew);
				ciShu += Double.valueOf(accountInfoNew.getNumber());
			}
		}
	}

	@Override
	public int getCount() {
		if(chargeAccountInfoNewList.size() == 0){
			count = 1;
		}else {
			if(chargeAccountInfoNewListJiFen.size() >=  1){
				jiFenCount = 1;
			}
			if(chargeAccountInfoNewListCiShu.size() >=1){
				ciShuCount = 1;
			}
			count = jiFenCount + ciShuCount;
		}
		return count;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return chargeAccountInfoNewList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup arg2) {
		View view = null;
		if(chargeAccountInfoNewList.size() < 1){
			view = View.inflate(activity, R.layout.chongzhi_account, null);
			xuni_account = (TextView)view.findViewById(R.id.xuni_account);
			xuni_account.setText("0");
		}/*else {
			if(contentView == null){
				view = View.inflate(activity, R.layout.chongzhi_account, null);
			}else {
				view = contentView;
			}
			xuni_account = (TextView)view.findViewById(R.id.xuni_account);
			if(position == 0 ){
				if(count == 2){
					xuni_account.setText(jiFen+"积分");
				}else if(count == 1){
					if(jiFenCount == 1 && ciShuCount == 0){
						xuni_account.setText(jiFen+"积分");
					}
					if(ciShuCount == 1 && jiFenCount == 0){
						xuni_account.setText(ciShu+"次数");
					}
				}
				
			}
			if(position == 1){
				xuni_account.setText(ciShu+"次数");
			}
		}*/
		else if(count == 1){
			if(contentView == null){
				view = View.inflate(activity, R.layout.chongzhi_account, null);
			}else {
				view = contentView;
			}
			xuni_account = (TextView)view.findViewById(R.id.xuni_account);
			if(jiFenCount == 1 && ciShuCount == 0){
				xuni_account.setText(new DecimalFormat("#0.00").format(jiFen)+"积分");
			}
			if(ciShuCount == 1 && jiFenCount == 0){
				xuni_account.setText((int)ciShu+"次数");
			}
		}else if(count == 2){
			if(contentView == null){
				view = View.inflate(activity, R.layout.chongzhi_account, null);
			}else {
				view = contentView;
			}
			xuni_account = (TextView)view.findViewById(R.id.xuni_account);
			rl_charge_account = (RelativeLayout)view.findViewById(R.id.rl_charge_account);
			if(position == 0 ){
				rl_charge_account.setBackgroundResource(R.drawable.item_top_white_shape);
				xuni_account.setText(new DecimalFormat("#.00").format(jiFen)+"积分");
			}
			if(position == 1){
				rl_charge_account.setBackgroundResource(R.drawable.item_bottom_white_shape);
				xuni_account.setText((int)ciShu+"次数");
			}
		}
		return view;
	}

}
